package com.xjnt.base.support.admin.entity;

import java.util.List;

import com.xjnt.frameworks.annotation.Entity;
import com.xjnt.frameworks.core.BaseModel;
import com.xjnt.frameworks.plugin.sql.criterion.Restrictions;
import com.xjnt.frameworks.plugin.sql.criterion.SqlCriteria;

/**
 * 系统字典表
 * @author caoyong
 *
 */
@Entity(tableName="sys_dictionary", primaryKey="uuid")
public class Dictionary extends BaseModel<Dictionary> {

	private static final long serialVersionUID = 1L;
	
	//属性定义
	public static final String PK_ID = "uuid";
	public static final String NAME = "name";
	public static final String CODE = "code";
	public static final String VALUE = "value";
	public static final String TYPE = "type"; //0目录,1字典,2种类型
	public static final String FK_PID = "parentid";
	public static final String CREATETIME = "create_time";
	public static final String UPDATETIME = "update_time";
	
	public static final Dictionary me = new Dictionary();
	
	public Dictionary getParent(){
		return findById(getStr(FK_PID));
	}
	
	public List<Dictionary> getChildren(){
		SqlCriteria criteria = new SqlCriteria(me);
		criteria.add(Restrictions.eq(FK_PID, getStr(PK_ID)));
		return find(criteria.toSelectSql(), getStr(PK_ID));
	}
}
